/*
 * @(#)StandardAutoLabelGenerator.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
     * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework;


/**
 * <p>Class Name:       StandardAutoLabelGenerator.java    </p>
 * <p>Description:      The class mainly handle the standard auto label generation logic.</p>
 * @author              Zoe Shum
 * @company             DCIVision Limited
 * @creation date       15/10/2003
 * @version             $Revision: 1.4 $
 */
public class StandardAutoLabelGenerator implements AutoLabelGenerator {

  public static final String REVISION = "$Revision: 1.4 $";

  public String sStartIndicator = "[";
  public String sEndIndicator = "]";

  private int startPos=0;
  private int endPos=0;
  public StandardAutoLabelGenerator(){
  }

  public String process(String template, Integer curRecordNo) throws ApplicationException {
    String genLabel = "";
    Integer maxNumber = curRecordNo;
    StringBuffer sb = new StringBuffer(template);
    
System.out.println("template = " + template + " Max Num = " + maxNumber);
    int startPos = template.indexOf("[");
    int endPos = template.lastIndexOf("]") +1;
System.out.println("startPos = " + startPos + " endPos = " + endPos);
    if (startPos >=0 && endPos>0) {
      String replaceTarget = template.substring(startPos, endPos);

      String sMaxNumber = TextUtility.formatNumberWithZeroPrefix(replaceTarget.
        length()-2, maxNumber);
System.out.println("replace Target = " + replaceTarget + " smaxNum = " +
                       sMaxNumber);
      sb.delete(startPos, endPos);
      sb.insert(startPos, sMaxNumber);
    }
    genLabel = sb.toString();

    return genLabel;
  }

}